/**
 * Created by sdh on 2017/1/1.
 */
var mongo = require('./db');
function Answer(name, second, askTitle, answer) {
    this.name = name;
    this.second = second;
    this.askTitle = askTitle;
    this.answer = answer;
}
Answer.prototype.save = function (callback) {
    var name = this.name;
    var second = this.second;
    var askTitle = this.askTitle;
    var answer = this.answer;
    //搜集一下信息
    mongo.open(function (err, db) {
        if (err) {
            return callback(err)
        }
        db.collection('asks', function (err, collection) {
            if (err) {
                mongo.close();
                return callback(err);
            }
            //保存提问到对应的提问的answers里面
            collection.update({
                "name": name,
                "time.second": second,
                "askTitle": askTitle
            }, {
                $push: ({"answers": answer})
            }, function (err) {
                mongo.close();
                if (err) {
                    return callback(err)
                }
                callback(null)
            })
        })
    })
}
module.exports = Answer;